package com.stylefeng.guns.common.transform;

import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.common.enu.BillStateEnum;
import com.stylefeng.guns.common.enu.BillTypeEnum;
import com.stylefeng.guns.common.persistence.model.Bill;
import com.stylefeng.guns.common.vo.BillVO;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BillTransform {

    public static BillVO transform(Bill bill){
        BillVO billVO = new BillVO();
        billVO.setId(bill.getId());
        billVO.setUserPerson(bill.getUserPerson());
        billVO.setPersonName(bill.getPersonName());
        billVO.setPersonPhone(bill.getPersonPhone());
        billVO.setType(bill.getType());
        billVO.setMoney(bill.getMoney());
        billVO.setRemark(bill.getRemark());
        billVO.setCreateTime(bill.getCreateTime());
        billVO.setCreateUser(bill.getCreateUser());
        billVO.setModifyUser(bill.getModifyUser());
        billVO.setModifyUser(bill.getModifyUser());
        billVO.setState(bill.getState());
        billVO.setCreateName(ConstantFactory.me().getUserNameById(bill.getCreateUser()));
        billVO.setStateName(BillStateEnum.getName(bill.getState()));
        billVO.setTypeName(BillTypeEnum.getName(bill.getType()));
        System.out.println("--------根据字典获取内容"+ ConstantFactory.me().getBillTypeName(bill.getType()));
        return billVO;
    }

    public static List<BillVO> transform(List<Bill> billList){
        if (billList == null || billList.isEmpty()){
            return Collections.emptyList();
        }
        List<BillVO> cds = new ArrayList<>();
        billList.forEach(bill -> cds.add(transform(bill)));
        return cds;
    }
}
